<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="Public:meta" />
</head>
<body id="main_page">
<include file="Public:position" />
<div class="container">
    <div class="box">
        <form action="{$Action}" method="post" id="frmAdd" enctype="multipart/form-data">
            <div class="box-header"><h4>投票基本信息</h4></div>
            <div class="box-content">
                <table class="boxtable">
                    <tr>
                        <th>投票名称</th>
                        <td><input type="text" class="textinput w450"  id="VoteName" name="VoteName" value="" /></td>
                    </tr>
                    <tr>
                        <th>触发关键词</th>
                        <td><input type="text" class="textinput" style="230px"  id="AppKeyword" name="AppKeyword" value="" />
                        <span class='Caution'>在微信输入此关键词，将返回当前应用的图文消息！</span>
                        </td>
                    </tr>
                <tr>
                    <th>图文消息封面</th>
                    <td><input type="text" id="wxvotepictureImage" class="textinput w450" name="VotePicture" value=""  />
                    <span class='UploadWrapper'>
                        <input class='btnFileUpload' type='button' value='上传' />
                        <input id='wxvotepicture' name ='wxvotepicture' type ='file'  size='70'   class='InputFile'  accept="image/*" />
                    </span>
                    <input id='btnServer' onclick='BrowserServer(1)' name ='btnServer'  type ='button' value='{$Think.lang.SelectPicture}'  class='btnUpload' />
                    </td>
                </tr>
                    <tr>
                        <th>投票简介</th>
                        <td>
                        <textarea class="w450" style="height:40px; width:100%" name="Description"></textarea>
                        </td>
                    </tr>
                   <tr>
                        <th>起止时间</th>
                        <td><script type='text/javascript' src='{$WebPublic}My97DatePicker/WdatePicker.js'></script>
                        <input name='StartTime' type='text' class='Wdate' id='StartTime'  class='textinput' style="width:140px"  onClick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly='readonly'   value='{$StartTime}' /><span style="padding:0px 5px">到</span><input name='EndTime' type='text' class='Wdate' id='EndTime'  class='textinput' style="width:140px"  onClick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly='readonly'   value='{$EndTime}' />
                        </td>
                    </tr>
               <tr>
                    <th nowrap="nowrap">是否多选</th>
                    <td>
                        <label><input type="radio" name="IsMultiple" value="1"   />多选</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label><input type="radio" name="IsMultiple" value="0"  checked="checked" />单选</label>
                    </td>
                </tr>
                   <tr>
                        <th nowrap="nowrap">投票结果</th>
                        <td>
                            <label><input type="radio" name="ShowResult" value="1" checked="checked"  /> 投票前可见</label>&nbsp;&nbsp;&nbsp;&nbsp;
                            <label><input type="radio" name="ShowResult" value="2"  />投票后可见</label>&nbsp;&nbsp;&nbsp;&nbsp;
                            <label><input type="radio" name="ShowResult" value="3"  />投票结束可见 </label>&nbsp;&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th nowrap="nowrap">是否启用</th>
                        <td>
                            <label><input type="radio" name="IsEnable" value="1" checked="checked"  />启用</label>&nbsp;&nbsp;
                            <label><input type="radio" name="IsEnable" value="0"  />禁用</label>
                        </td>
                    </tr>
                  </table>
            </div>
            
            <div class="box-header"><h4>投票项</h4></div>
            <div class="box-content">
                <table class="boxtable" id="allitems">
                    <tr>
                        <th>投票项1</th>
                        <td>
                        <input type="hidden"  name="ItemID[]" value="0" />
                        <input type="text" class="textinput w450" name="ItemName[]" value="" />
                        &nbsp;<a onclick="delItem(this)">[-删除投票项]</a>
                        </td>
                    </tr>
                   <tr>
                        <th>投票项2</th>
                        <td>
                        <input type="hidden"  name="ItemID[]" value="0" />
                        <input type="text" class="textinput w450" name="ItemName[]" value="" />
                        &nbsp;<a onclick="delItem(this)">[-删除投票项]</a></td>
                    </tr>
                   <tr>
                        <th>投票项3</th>
                        <td>
                        <input type="hidden"  name="ItemID[]" value="0" />
                        <input type="text" class="textinput w450" name="ItemName[]" value="" />
                        &nbsp;<a onclick="delItem(this)">[-删除投票项]</a></td>
                    </tr>
                </table>
                <table class="boxtable" id="addItem">
                    <tr>
                        <th></th>
                        <td><a onclick="addItem()">[+添加投票项]</a></td>
                    </tr>
                </table>
           </div>

            <div class="box-footer">
                <div class="box-footer-inner">
                    <input  id="btnSubmit" class="marginright" type="submit"  value="保存并继续添加" />
                    <input  id="btnSubmit"  type="button" value="返回" class="GoBack"  onclick="GoBack()" />
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
<script type='text/javascript'>
function BrowserServer(){
	var finder = new CKFinder();
	finder.basePath = '{$WebPublic}ckfinder'; 
	finder.selectActionFunction = SetPictureField;
	//alert('d'); //加上alert指令后，popup都能弹出对话框
	finder.popup(); 
}

function SetPictureField(fileUrl){
	document.getElementById('wxvotepictureImage').value = fileUrl;
}

$(document).ready(function(){
	$('#frmAdd').ajaxForm({
		success: complete,
		dataType: 'json'
	});
	
	function complete(data){
		CloseLoadBox();
		if (data.status==1){
			SucceedBox(data.info);
			$('#frmAdd').resetForm();
			$('#VoteName').focus();
		}else if(data.status==0){
			ErrorBox(data.info);
		}else if(data.status==2){
			ErrorBox(data.info); //上传失败
		}else if(data.status==3){
			$('#'+data.data.ImageField).val(data.data.Path);
			SucceedBox(data.info); //上传成功
		}
	};
	
	 $('#frmAdd').submit(function(){
		LoadBox();
		return false;  //为了防止普通浏览器进行表单提交和产生页面导航（防止页面刷新？）返回false  
	 });
	 
	 $('#wxvotepicture').change(function(){
		 if( !$(this).val() ) return;
		$('#frmAdd').attr('action','{$UploadAction}/currentfile/wxvotepicture');
		$('#frmAdd').submit();
	 });
	 
	 $('#btnSubmit').click(function(){
		$('#frmAdd').attr('action','{$Action}');
	 });
	 
	 $("#wxvotepictureImage").powerFloat({
		targetMode: "ajax",
		targetAttr: "value",
		position: "5-7"
	 });
	 
	 $('#VoteName').focus();
	 
});

function GoBack(){
	window.location.href = "{$Url}vote";
}
//添加一个项目
function addItem(){
	var oTh = $("#allitems th");
	var i = oTh.length + 1;
	var item="<tr><th>投票项"+i+"</th><td>";
	item += "<input type='text' class='textinput w450' name='ItemName[]' value='' />";
	item += "<input type='hidden'  name='ItemID[]' value='0' />";
	item += "&nbsp;<a onclick='delItem(this)'>[-删除投票项]</a></td></tr>";
	$("#allitems").append(item);
	$("#allitems input[name='ItemName[]']").last().focus();
}

function delItem(obj){
	$(obj).parent().parent().remove();
	var oTh = $("#allitems th");
	for(var i=0; i< oTh.length; i++){
		var txt ="投票项目"+(i+1).toString();
		$(oTh[i]).text(txt);
	}
}
</script>